package lbframework.bean.tree;

import java.util.Vector;

public class LBItemNode {

    private String descricao;
    public int selecionado = 0;
    private Vector<LBItemNode> children = new Vector();

    public void addChild(LBItemNode i_folder) {
        children.add(i_folder);
    }

    //private void fillCache() {
        /*String[] images = new File(fullPath).list(PicturesOnlyFilter.getInstance());
        if (images != null)
        imagesCount = images.length;

        String[] childs = new File(fullPath).list(FoldersOnlyFilter.getInstance());

        if (childs != null) {
        // all childs are directories
        children = new ArrayList<FolderBean>(childs.length);
        Arrays.sort(childs, String.CASE_INSENSITIVE_ORDER);
        for (String child : childs) {
        children.add(new FolderBean(fullPath + "\\" + child, child, isChecked));
        }
        } else {
        children = new ArrayList<FolderBean>(0);
        }*/
        
        //children = new Vector();
    //}

    public LBItemNode(String i_descricao, int i_selecionado) {
        this.descricao = i_descricao;
        this.selecionado = i_selecionado;
    }

    /*public FolderBean(String node, File[] childs, boolean isChecked) {
    this(node, node, isChecked);
    children = new ArrayList<FolderBean>(childs.length);
    Arrays.sort(childs, new FileNameCaseInsensitiveComparator());
    for (File child : childs) {
    try {
    children.add(new FolderBean(child.getCanonicalPath(), child.getName(), isChecked));
    } catch (IOException ex) {
    }
    }
    }*/
    public LBItemNode getChild(int index) {
        //if (children == null) {
            //fillCache();
        //}
        return children.get(index);
    }

    public int getChildCount() {
        //if (children == null) {
            //fillCache();
        //}
        return children.size();
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String i_descricao) {
        this.descricao = i_descricao;
    }

    public int getSelecionado() {
        return selecionado;
    }

    public void setSelecionado(int i_selecionado) {
        this.selecionado = i_selecionado;

        if (children != null) {
            for (LBItemNode child : children) {
                child.setSelecionado(i_selecionado);
            }
        }
    }

    @Override
    public String toString() {
        return this.descricao;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof LBItemNode) {
            LBItemNode o = (LBItemNode) obj;
            return o.getDescricao().equals(this.descricao);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return descricao.hashCode();
    }

    /*private class FileNameCaseInsensitiveComparator implements Comparator<File> {

    @Override
    public int compare(File f1, File f2) {
    return f1.getName().compareToIgnoreCase(f2.getName());
    }
    }*/
}